package com.wangtao.firstapp.adapters;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.wangtao.firstapp.R;
import com.wangtao.firstapp.modles.GalleryEntity;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * 显示本地相册的适配器
 * Created by lanouhn on 16/9/5.
 */
public class GalleryAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<GalleryEntity> arrayList;

    public GalleryAdapter(Context context, ArrayList<GalleryEntity> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return arrayList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        if (convertView == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_takephoto, null);
        } else {
            view = convertView;
        }
        GalleryEntity galleryEntity = arrayList.get(position);
        ImageView iv_item_takephoto = (ImageView) view.findViewById(R.id.iv_item_takephoto);
        if (position == 0) {
            Picasso.with(context).load(R.mipmap.ic_album_camera).config(Bitmap.Config.RGB_565).into(iv_item_takephoto);
        } else {
            Picasso.with(context).load(galleryEntity.getUri()).config(Bitmap.Config.RGB_565).into(iv_item_takephoto);
        }
        return view;
    }
}
